package com.example.tenant.config;

import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.support.ExcelTypeEnum;
import org.springframework.stereotype.Component;

import java.io.InputStream;

@Component
public class ExcelReaderUtil {

    public <T> void readExcelFile(InputStream inputStream, Class<T> clazz, MyBaseMapper<T> mapper) {
        try {
            // 创建一个监听器，并传入服务实现
            GenericListener<T> listener = new GenericListener<>(mapper);
            EasyExcel.read(inputStream, clazz, listener).excelType(ExcelTypeEnum.XLSX).sheet().doRead();
        } catch (Exception e) {
            throw new RuntimeException("读取Excel文件时发生错误: " + e.getMessage(), e);
        }
    }
}
